package com.hut.oa.model.bean;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 申请表
 * @author 熊涛
 *
 */
@Entity
@Table(name="apply_")
public class Apply {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="a_id")
	private Long id;//申请表id
	
	@Column(name="a_title",nullable=false)
	private String title;//申请标题
	
	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="a_user_id",nullable=false)
	private User user;//申请用户
	
	@Column(name="a_time")
	private Date time=new Date();//发布时间
	
	@Column(name="a_status")
	private Integer status=0;//审核状态
	
	@Column(name="a_is_delete")
	private Integer isdelete=0;//是否放入回收站
	
	@JsonIgnore
	@OneToMany(cascade=CascadeType.ALL,mappedBy="apply")
	private List<ApplyRecord> applyRecord;//审核记录
	
	@OneToOne
	@JoinColumn(name="a_office_id",nullable=false)
	private DeptOffice deptOffice;//当前到哪个审批职位
	
	@ManyToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY)
	@JoinTable(name = "apply_office",
	    joinColumns = {
	            @JoinColumn(name = "ao_apply_id")
	    }, inverseJoinColumns = {
	    @JoinColumn(name = "ao_office_id")
	})
	private List<DeptOffice> deptOffices;//所有参与的职位
	
	@OneToOne(mappedBy="apply",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private ApplyObject applyObject;//物品申请
	
	@OneToOne(mappedBy="apply",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private ApplyAccount applyAccount;//报销申请
	
	@OneToOne(mappedBy="apply",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private ApplyBusiness applyBusiness;//出差申请
	
	@OneToOne(mappedBy="apply",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private ApplyLeave applyLeave;//请假申请
	
	@OneToOne(mappedBy="apply",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private Applywork applywork;//工作申请
	
	@OneToOne(mappedBy="apply",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private ApplyOther applyOther;//其他申请
	
	public Apply() {}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public Integer getIsdelete() {
		return isdelete;
	}

	public void setIsdelete(Integer isdelete) {
		this.isdelete = isdelete;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public DeptOffice getDeptOffice() {
		return deptOffice;
	}

	public void setDeptOffice(DeptOffice deptOffice) {
		this.deptOffice = deptOffice;
	}

	public List<ApplyRecord> getApplyRecord() {
		return applyRecord;
	}

	public void setApplyRecord(List<ApplyRecord> applyRecord) {
		this.applyRecord = applyRecord;
	}

	public List<DeptOffice> getDeptOffices() {
		return deptOffices;
	}

	public void setDeptOffices(List<DeptOffice> deptOffices) {
		this.deptOffices = deptOffices;
	}

	public ApplyObject getApplyObject() {
		return applyObject;
	}

	public void setApplyObject(ApplyObject applyObject) {
		this.applyObject = applyObject;
	}

	public ApplyAccount getApplyAccount() {
		return applyAccount;
	}

	public void setApplyAccount(ApplyAccount applyAccount) {
		this.applyAccount = applyAccount;
	}

	public ApplyBusiness getApplyBusiness() {
		return applyBusiness;
	}

	public void setApplyBusiness(ApplyBusiness applyBusiness) {
		this.applyBusiness = applyBusiness;
	}

	public ApplyLeave getApplyLeave() {
		return applyLeave;
	}

	public void setApplyLeave(ApplyLeave applyLeave) {
		this.applyLeave = applyLeave;
	}

	public Applywork getApplywork() {
		return applywork;
	}

	public void setApplywork(Applywork applywork) {
		this.applywork = applywork;
	}

	public ApplyOther getApplyOther() {
		return applyOther;
	}

	public void setApplyOther(ApplyOther applyOther) {
		this.applyOther = applyOther;
	}

	@Override
	public String toString() {
		return "Apply [id=" + id + ", title=" + title + ", time=" + time + ", status=" + status + ", isdelete="
				+ isdelete + "]";
	}

}
